package com.liyiqing.secondhandmall.memberservice.service.impl;

import com.liyiqing.commonservice.utils.R;
import com.liyiqing.commonservice.utils.StatusCode;
import com.liyiqing.secondhandmall.memberservice.entity.MemberUserEntity;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.liyiqing.commonservice.utils.PageUtils;
import com.liyiqing.commonservice.utils.Query;

import com.liyiqing.secondhandmall.memberservice.dao.MemberUserReceiveAddressDao;
import com.liyiqing.secondhandmall.memberservice.entity.MemberUserReceiveAddressEntity;
import com.liyiqing.secondhandmall.memberservice.service.MemberUserReceiveAddressService;

import javax.annotation.Resource;


@Service("memberUserReceiveAddressService")
public class MemberUserReceiveAddressServiceImpl extends ServiceImpl<MemberUserReceiveAddressDao, MemberUserReceiveAddressEntity> implements MemberUserReceiveAddressService {

    @Resource
    private MemberUserReceiveAddressDao receiveAddressDao;


    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<MemberUserReceiveAddressEntity> page = this.page(
                new Query<MemberUserReceiveAddressEntity>().getPage(params),
                new QueryWrapper<MemberUserReceiveAddressEntity>()
        );

        return new PageUtils(page);
    }




    @Override
    public R selectAllReceiveAddress() {
        List<MemberUserReceiveAddressEntity> list = receiveAddressDao.selectList(null);
        if (list == null || list.size()==0){
            return R.error(StatusCode.DATA_NOT_FOUND.getCode(),StatusCode.DATA_NOT_FOUND.getMsg());
        }
        return R.ok().put("data", list);
    }


    @Override
    public R selectReceiveAddressById(Long id) {
        MemberUserReceiveAddressEntity receiveAddress = receiveAddressDao.selectById(id);
        if (receiveAddress == null){
            return R.error(StatusCode.DATA_NOT_FOUND.getCode(),StatusCode.DATA_NOT_FOUND.getMsg());
        }
        return R.ok().put("data", receiveAddress);
    }


    @Override
    public R selectAddressByMemberId(Long memberId) {
        List<MemberUserReceiveAddressEntity> list = receiveAddressDao.selectAddressByMemberId(memberId);
        if (list == null || list.size() ==0){
            return R.error(StatusCode.DATA_NOT_FOUND.getCode(),StatusCode.DATA_NOT_FOUND.getMsg());
        }
        return R.ok().put("data",list);

    }
}